<?php

class DateHelper {

    /**
     * Returns the date with format to use it in SQL expressions
     * @param $date
     * @return string
     */
    public static function changeDateFormatToSql($date) {
        if($date == NULL || $date == '')
            return '';

        return DateHelper::changeDateFormat($date, 'd/m/Y', 'Y-m-d');
    }

    /**
     * Returns the date with format to use it in SQL expressions
     * @param $date
     * @param $oldFormat
     * @param $newFormat
     * @return string
     */
    public static function changeDateFormat($date, $oldFormat, $newFormat) {
        return DateTime::createFromFormat($oldFormat, $date)->format($newFormat);
    }

    /**
     * Returns a date added a given amount of minutes
     * @param $date
     * @param $minutes
     * @param $format
     * @return date
     */
    public static function addMinutesToDate($date, $minutes, $format = 'H:i:s') {
        $CONVERT_MINUTES_TO_SECONDS = 60;
        return date($format, strtotime($date) + $CONVERT_MINUTES_TO_SECONDS * $minutes);
    }
}
